<?php

namespace common\models\projectsummary;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\projectsummary\ProjectSummary;

/**
 * ProjectSummarySearch represents the model behind the search form about `common\models\projectsummary\ProjectSummary`.
 */
class ProjectSummarySearch extends ProjectSummary
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'category', 'starttime', 'endtime'], 'integer'],
            [['number', 'name', 'cname', 'bearunit', 'amount_subsidy', 'proj_leader', 'proj_telephone', 'proj_summ', 'registration_form', 'bear_option', 'mana_option', 'depart_leader', 'total_appropriation', 'surplus', 'actual_item', 'paid_money', 'paid_note', 'fina_leader', 'lister', 'file_name', 'file_description', 'proj_size'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = ProjectSummary::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
            'category' => $this->category,
            'starttime' => $this->starttime,
            'endtime' => $this->endtime,
        ]);

        $query->andFilterWhere(['like', 'number', $this->number])
            ->andFilterWhere(['like', 'name', $this->name])
            ->andFilterWhere(['like', 'cname', $this->cname])
            ->andFilterWhere(['like', 'bearunit', $this->bearunit])
            ->andFilterWhere(['like', 'amount_subsidy', $this->amount_subsidy])
            ->andFilterWhere(['like', 'proj_leader', $this->proj_leader])
            ->andFilterWhere(['like', 'proj_telephone', $this->proj_telephone])
            ->andFilterWhere(['like', 'proj_summ', $this->proj_summ])
            ->andFilterWhere(['like', 'registration_form', $this->registration_form])
            ->andFilterWhere(['like', 'bear_option', $this->bear_option])
            ->andFilterWhere(['like', 'mana_option', $this->mana_option])
            ->andFilterWhere(['like', 'depart_leader', $this->depart_leader])
            ->andFilterWhere(['like', 'total_appropriation', $this->total_appropriation])
            ->andFilterWhere(['like', 'surplus', $this->surplus])
            ->andFilterWhere(['like', 'actual_item', $this->actual_item])
            ->andFilterWhere(['like', 'paid_money', $this->paid_money])
            ->andFilterWhere(['like', 'paid_note', $this->paid_note])
            ->andFilterWhere(['like', 'fina_leader', $this->fina_leader])
            ->andFilterWhere(['like', 'lister', $this->lister])
            ->andFilterWhere(['like', 'file_name', $this->file_name])
            ->andFilterWhere(['like', 'file_description', $this->file_description])
            ->andFilterWhere(['like', 'proj_size', $this->proj_size]);

        return $dataProvider;
    }
}
